# Station从0,0开始编号
# A=[[A0],[A1]]，其中A[0][0]与A[1][0]已经吸收了e1与e2的值
# A[0][n-1]与A[1][n-1]已经吸收了x1与x2的值
def fastest_way(A,T):
    n=len(A[0])
    F=[[0 for i in xrange(n)],[0 for i in xrange(n)]]
    L=[[None for i in xrange(n-1)],[None for i in xrange(n-1)]]
    F[0][0]=A[0][0]
    F[1][0]=A[1][0]
    for i in xrange(1,n):
        if F[0][i-1]+A[0][i]<=F[1][i-1]+T[1][i-1]+A[0][i]:
            F[0][i]=F[0][i-1]+A[0][i]
            L[0][i-1]=0 #F[0][i]的前项是L[0][i-1]
        else:
            F[0][i]=F[1][i-1]+T[1][i-1]+A[0][i]
            L[0][i-1]=1
        if F[1][i-1]+A[1][i]<=F[0][i-1]+T[0][i-1]+A[1][i]:
            F[1][i]=F[1][i-1]+A[1][i]
            L[1][i-1]=1
        else:
            F[1][i]=F[0][i-1]+T[0][i-1]+A[1][i]
            L[1][i-1]=0
    if F[0][-1]<=F[1][-1]:
        lstar=0
    else:
        lstar=1
    return L,lstar
def print_stations(L,lstar):
    i=lstar
    print 'line',i,', station', len(L[0]) #最后1个Station
    for j in xrange(len(L[0])-1,-1,-1):
        i=L[i][j] #F[i][j+1]的前项
        print 'line',i,', station', j
def print_stations_recursive(L,current,j):
    if j==0:
        print 'line',current,', station', j
        return
    prev=L[current][j-1] #F[i][j]的前项
    print_stations_recursive(L,prev,j-1)
    print 'line',current,', station', j
def do_print_stations(L,lstar):
    n=len(L[0])+1
    print_stations_recursive(L,lstar,n-1)
    

if __name__=='__main__':
    A=[[2+7,9,3,4,8,4+3],\
       [4+8,5,6,4,5,7+2]]
    T=[[2,3,1,3,4],\
       [2,1,2,2,1]]
    L,lstar=fastest_way(A,T)
    do_print_stations(L,lstar)
